<?php

/*
 *
 */

include_once('framework/DataAccessObject.php');

class TagsDAO extends DataAccessObject
{
	function addTag($photoId, $tagText)
	{
		$alreadyExists = $this->db->executeField("SELECT COUNT(*) FROM tags WHERE id=? AND tag_text=?", array($photoId, $tagText)) > 0;
		if (!$alreadyExists)
		{
			return $this->db->execute("INSERT INTO tags VALUES (?, ?)", array($photoId, $tagText));
		}
	}

	function getTags($photoId)
	{
		return $this->db->executeSet("SELECT tag_text FROM tags WHERE id=?", array($photoId));
	}

	function getTaggedPhotos($tagText)
	{
		return $this->db->executeSet("SELECT id FROM tags WHERE tag_text=?", array($tagText));
	}


	function getAllTags()
	{
		return $this->db->executeSet("SELECT DISTINCT(tag_text) FROM tags", array());
	}

	function deleteAllTags($photoId)
	{
		return $this->db->execute("DELETE FROM tags WHERE id=?", array($photoId));
	}
}
?>
